package br.org.cesar.common;

import junit.framework.Assert;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * 
 * @author Haelysan
 *
 */

/*
 * Executa todas as acoes na pagina Inicial
 */
public class SomaRandomNumbers {

	/*
	 * Instancia privada do webDriver que vira da suite de teste
	 */
	private static final WebDriver driver;
	private static final WebDriverWait wait;

	/*
	 * Construtor que ira adicionar a instancia do WebDriver para utilizacao dos metodos
	 */
	static {
		driver = Selenium.getDriver();
		wait = new WebDriverWait(driver, 10);
	}
	
	static By valor1 = By.id("number1");
	static By valor2 = By.id("number2");
	static By enterValor = By.name("soma");
	static By sendButton = By.name("submit");
	static By verifyText = By.id("resultado");
			
	public SomaRandomNumbers() {
	}

	/**
	 * calculate
	 */
	public static void calculate(){
		String valor1 = driver.findElement(By.id("number1")).getText();
		String valor2 = driver.findElement(By.id("number2")).getText();
		
		int resultadoInt = Integer.parseInt(valor1) + Integer.parseInt(valor2);
		
		driver.findElement(enterValor).sendKeys(String.valueOf(resultadoInt));
		driver.findElement(sendButton).click();
	}	
	/**
	 * Verify text result
	 */
	
	public static void verifyTextResult(){
		wait.until(ExpectedConditions.visibilityOfElementLocated(verifyText));
		Assert.assertEquals("CORRETO", driver.findElement(verifyText).getText());
	}

}